package com.lyshop.jinxiang.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;


import com.lyshop.jinxiang.R;
import com.lyshop.jinxiang.adapters.BankListAdapter;
import com.lyshop.jinxiang.base.BaseActivity;
import com.lyshop.jinxiang.bean.BankListBean;
import com.lyshop.jinxiang.net.ActionCallbackListener;
import com.lyshop.jinxiang.utils.RouteUtil;
import com.lyshop.jinxiang.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class BankListActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    private ListView lv_bank_list;
    private List<BankListBean> mBankList = new ArrayList<>();
    private String mCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mCode = getIntent().getExtras().getString(RouteUtil.BUNDLE_RECHARGE_CODE);
    }

    @Override
    protected void onResume() {
        //MobclickAgent.onPageStart("选择银行");
        super.onResume();
        if (mBankList.size() == 0) {
            mAppAction.getBankList(mCode, new ActionCallbackListener<List<BankListBean>>() {
                @Override
                public void onSuccess(List<BankListBean> data) {
                    mBankList = data;
                    BankListAdapter adapter = new BankListAdapter(BankListActivity.this, mBankList);
                    lv_bank_list.setAdapter(adapter);
                }

                @Override
                public void onFailure(String errorCode, String message) {
                    ToastUtil.showToast(mContext, message);
                }
            });
        }
    }

    @Override
    protected void onPause() {
        //MobclickAgent.onPageEnd("选择银行");
        super.onPause();
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_bank_list;
    }

    @Override
    protected void findViews() {
        lv_bank_list = (ListView) findViewById(R.id.lv_bank_list);
    }

    @Override
    protected void setListeners() {
        lv_bank_list.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent = new Intent();
        intent.putExtra(RouteUtil.BUNDLE_BANK_MODEL, mBankList.get(i));
        setResult(RESULT_OK, intent);
        backActivity();
    }
}